package com.sumainfor.pc.market.controller.rentadviser;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.RdHousingInfoService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Date 2018年11月7日
 * @Describe 市场部房源详表
 */
@RestController
@RequestMapping("/rentadviser/RdHousingInfoController")
public class RdHousingInfoController implements Serializable {
    @Autowired
    private RdHousingInfoService rdHousingInfoService;

    /**
     * 查询整套房源房间信息
     */
    @GetMapping("/getHousingHouInfoIdAllByHouId")
    public JsonResult getHousingHouInfoIdAllByHouId(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = rdHousingInfoService.getHousingHouInfoIdAllByHouId(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 查询整套房源房间信息
     */
    @GetMapping("/getHousingInfoListByHouInfoId")
    public JsonResult getHousingInfoListByHouInfoId(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = rdHousingInfoService.getHousingInfoListByHouInfoId(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 根据房间id查询整套房源房间信息及房间配置和公共区域配置信息
     */
    @GetMapping("/getHousingInfoByHouInfoId")
    public JsonResult getHousingInfoByHouInfoId(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        Map<String, Object> map = rdHousingInfoService.getHousingInfoByHouInfoId(params);
        if (map != null) {
            result.put(map);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 根据房源编号查询房间的信息
     */
    @GetMapping("/getHousingHouInfoIdByHouConId")
    public JsonResult getHousingHouInfoIdByHouConId(@RequestParam Map<String, Object> params) {
        return  rdHousingInfoService.getHousingHouInfoIdByHouConId(params);

    }

    /**
     * 房源上架
     */
    @PostMapping("/updateHousingHouInfo")
    public JsonResult updateHousingHouInfo(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        return rdHousingInfoService.updateHousingHouInfo(params);
    }

    /**
     * 房源下架
     */
    @PostMapping("/updateHousingHouInfoDown")
    public JsonResult updateHousingHouInfoDown(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        return rdHousingInfoService.updateHousingHouInfoDown(params);
    }

    /**
     * 签约根据房源详表编号查询房源的配置 合租
     */
    @GetMapping("/getHouConListByHouConIdP")
    public JsonResult getHouConListByHouConIdP(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = rdHousingInfoService.getHouConListCountByHouConIdP(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = rdHousingInfoService.getHouConListByHouConIdP(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 签约根据房源编号查询房源的配置 整租
     */
    @GetMapping("/getHouConListByHouIdZ")
    public JsonResult getHouConListByHouIdZ(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = rdHousingInfoService.getHouConListCountByHouIdZ(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = rdHousingInfoService.getHouConListByHouIdZ(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 查询盈利预测拆分间数的总和
     */
    @GetMapping("/getCountForHouInfo")
    public JsonResult getCountForHouInfo() {
        JsonResult result = new JsonResult();
        Integer count = rdHousingInfoService.getCountForHouInfo();
        if (count != null) {
            result.put(count);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 运营部录入水电燃费时查询已经签约房源的信息
     *
     * @param params
     * @param pager
     * @return
     */
    @PostMapping("/key/getHouInfoListForEwg")
    public JsonResult getHouInfoListForEwg(@RequestBody Map<String, Object> params
            , Pager pager) {
        System.out.println("pager:" + pager);
        System.out.println("params:" + params);
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        String a = "";
        if (params.get("ifOperaType") != null) {
            a = params.get("ifOperaType").toString();
        }
        if (a.equals("")) {//是否整租
            params.put("ifOperaList", null);
        } else {
            params.put("ifOperaList", a.split(","));
        }
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = rdHousingInfoService.getHouInfoListCountForEwg(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = rdHousingInfoService.getHouInfoListForEwg(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /*
     *运营部服务秘书查询账单管理
     * */
    @PostMapping("/key/getHouInfoListForBillParticular")
    public JsonResult getHouInfoListForBillParticular(@RequestBody Map<String, Object> params) {
        Pager pager = new Pager();
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        System.out.println("pager:" + pager);
        System.out.println("params:" + params);
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = rdHousingInfoService.getHouInfoListCountForEwg(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = rdHousingInfoService.getHouInfoListForEwg(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        System.out.println("返回给运营部的数据:"+result);
        return result;
    }

    /**
     * 运营部录入水电燃费时查询已经签约房源的信息
     */
    @PostMapping("/key/getHouInfoListForGmio")
    public JsonResult getHouInfoListForGmio(@RequestBody Map<String, Object> params) {
        String a = params.get("ifOperaType").toString();
        if (a.equals("")) {//是否整租
            params.put("ifOperaList", null);
        } else {
            params.put("ifOperaList", a.split(","));
        }
        JsonResult result = new JsonResult();
        List<Map<String, Object>> lsit = rdHousingInfoService.getHouInfoListForGmio(params);
        if (lsit != null) {
            result.put(lsit);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 运营部录入水电燃费时查询已经签约房源的信息
     */
    @PostMapping("/key/getHouInfoListForGmioTcmkt")
    public JsonResult getHouInfoListForGmioTcmkt(@RequestBody Map<String, Object> params) {
        return rdHousingInfoService.getHouInfoListForGmioTcmkt(params);
    }

    /**
     * 运营部租后主管退租账单
     *
     * @param params
     * @return
     */
    @PostMapping("/key/getHouInfoListForDbill")
    public JsonResult getHouInfoListForDbill(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        if(MapUtils.getInteger(params,"zczsStatus")==null) {
            String a = params.get("ifOperaType").toString();
            if (a.equals("")) {//是否整租
                params.put("ifOperaList", null);
            } else {
                params.put("ifOperaList", a.split(","));
            }
        }
            System.out.println("接收到的参数:" + params);
            Map<String, Object> map = rdHousingInfoService.getHouInfoListForDbill(params);
            if (map != null) {
                result.put(map);
            } else {
                result.putFailed("服务器繁忙");
            }

        return result;
    }


    /**
     * 租赁顾问工单管理输入房源编号查询项目
     */
    @GetMapping("/getHousingInfoIdList")
    public JsonResult getHousingInfoIdList(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = rdHousingInfoService.getHousingInfoIdList(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /*
     *运营部根据房源编号查询房源的合同截止日期和合同编号
     */
    @GetMapping("/getPactInfoByHouInfoId")
    public JsonResult getPactInfoByHouInfoId(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        Map<String, Object> map = rdHousingInfoService.getPactInfoByHouInfoId(params);
        if (map != null) {
            result.put(map);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /*
     *运营部根据房源详表编号查询该房源签约业主的所有合同
     */
    @GetMapping("/getPactIdListByHouInfoId")
    public JsonResult getPactIdListByHouInfoId(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = rdHousingInfoService.getPactIdListByHouInfoId(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 运营租后主管查询账单审核列表
     */
    @PostMapping("/key/getHouInfoListForDi")
    public JsonResult getHouInfoListForDi(@RequestBody Map<String, Object> params) {
        System.out.println("接收到的参数:" + params);
        JsonResult result = new JsonResult();
        Map<String, Object> map = rdHousingInfoService.getHouInfoListForDi(params);
        if (map != null) {
            result.put(map);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 服务管家根据房源编号查询该房源所签署的合同信息
     */
    @GetMapping("/getHouPactByHouInfoId")
    public JsonResult getHouPactByHouInfoId(@RequestParam Map<String, Object> params) {
        return rdHousingInfoService.getHouPactByHouInfoId(params);
    }

    /**
     * 运营部租后主管退租账单
     *
     * @param params
     * @return
     */
    @PostMapping("/key/getHoulivecardList")
    public JsonResult getHoulivecardList(@RequestBody Map<String, Object> params) {
        System.out.println("接收到的参数:" + params);
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = rdHousingInfoService.getHoulivecardList(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     * 租客端查询临时账单列表
     */
    @PostMapping("/key/getHouTemporaryList")
    public JsonResult getHouTemporaryList(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = rdHousingInfoService.getHouTemporaryList(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     * 服务管家根据房源编号查询该房源所签署的合同信息
     */
    @PostMapping("/getRdHousingInfoListByHouInfoId")
    public JsonResult getRdHousingInfoListByHouInfoId(@RequestBody Map<String, Object> params) {
        return rdHousingInfoService.getRdHousingInfoListByHouInfoId(params);
    }

}
